#!/bin/bash
prepobcppexecutable=/home/eduardo/projects/mestrado/pobcpp/pork/prepobcpp
pobcppexecutable=/home/eduardo/projects/mestrado/pobcpp/pork/pobcppc
src=$1
pobcpp=$2
suffix=".temp.cpp"
temp=$src$suffix
temp2=${src/".h"/".pob.h"}
temp2=${temp2/".cpp"/".pob.cpp"}
#temp2=$src".prepob"
if [ -e $src ]; then
	echo "#include \"pobcpp_preheader.h\"" > $temp
	cat "$src" >> $temp
	g++-4.1.2  -mmmx -msse2 -msse -I $pobcpp $3 $4 $5 $6 $7 $8 $9 -E -Wp,-K $temp > $temp".ii"
#	g++-4.2.4 -mmmx -msse2 -msse -I $pobcpp $3 $4 $5 $6 $7 $8 $9 -E $temp > $temp".ii"
#	mcpp -I- -I /usr/lib64/gcc/x86_64-pc-linux-gnu/4.1.2/include/g++-v4/ -I $pobcpp -+ -K $temp > $temp".ii"
  echo $prepobcppexecutable "$temp"".ii" "$temp"
  $prepobcppexecutable "$temp"".ii" "$temp" > "$temp"".patch"
  cp "$temp" "$src"".patched.cpp"
	rm "$temp"".ii" "$temp"
  cp "$src" "$src"".patched.cpp"
  patch --quiet "$src"".patched.cpp" "$temp"".patch"
#  rm "$temp"".patch"
	touch $temp2
	echo "#include \"pobcpp_postheader.h\"" > $temp2
	cat "$src"".patched.cpp" >> $temp2
	echo $temp2 " generated."
else
	echo "File not found."
fi
